 using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

/// <summary>
/// Summary description for PromotionsBuisness
/// </summary>
public class PromotionsBuisness
{
	public PromotionsBuisness()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public bool Insert(PromotionsEntities item)
    {
        bool flat = false;
        string[] para = { "@promotionsName", "@promotionsContent", "@promotionsFactor" };
        string[] values = {item._promotionsName,item._promotionsContent,item._promotionsFactor.ToString()};
        if (DataAccess.getExecProcedure("sp_InsertPromotions", para, values) > 0)
        {
            flat = true;
        }
        else
            flat = false;
        return flat;
    }

    public bool Edit(PromotionsEntities item)
    {
        bool flat = false;
        string[] para = { "@promotionsID", "@promotionsName", "@promotionsContent", "@promotionsFactor" };
        string[] values = { item._promotionsID.ToString(),item._promotionsName,item._promotionsContent,item._promotionsFactor.ToString() };
        if (DataAccess.getExecProcedure("sp_UpdatePromotions", para, values) > 0)
            flat = true;
        else
            flat = false;
        return flat;
    }

    public bool Delete(PromotionsEntities item)
    {
        if (DataAccess.getExecProcedure("sp_DeletePromotions", new string[] { "@promotionsID" }, new string[] { item._promotionsID.ToString() }) > 0)
            return true;
        else
            return false;
    }

    public DataTable getAllPromotions()
    {
        return DataAccess.DataTable_Query("exec sp_GetPromotions '0'");
    }

    public PromotionsEntities getPromotions(int promotionsID)
    {
        PromotionsEntities pre = new PromotionsEntities();
        DataTable dt = DataAccess.DataTable_Query("exec sp_GetPromotions '" + promotionsID + "'");
        if (dt != null)
        {
            DataRow dr = dt.Rows[0];
            pre._promotionsID = int.Parse(dr["promotionsID"].ToString());
            pre._promotionsName = dr["promotionsName"].ToString();
            pre._promotionsContent = dr["promotionsContent"].ToString();
            pre._promotionsFactor = Convert.ToDouble(dr["promotionsFactor"].ToString());
        }
        return pre;
    }

    public DataTable getPromotionsBy(string[] TableName, string[] fields, string Criterias, string priorities)
    {
        DataTable dt = new DataTable();
        string query = SQLQuery.SQLQuery_SELECT(TableName, fields, Criterias, priorities);
        return dt = DataAccess.DataTable_Query(query);
    }
    ----------
}